﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.IO;
using System.Drawing;
using System.Drawing.Imaging;

namespace ChartControls
{
    public class ChartHttpModule : IHttpModule
    {
        #region IHttpModule Members

        public void Dispose()
        {
            throw new NotImplementedException();
        }

        public void Init(HttpApplication context)
        {
            context.BeginRequest += new EventHandler(context_BeginRequest);
        }

        void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication app = sender as HttpApplication;

            if (app.Request.Path.Contains("getimage.aspx"))
            {
                app.Response.ContentType = "image/gif";

                app.Context.ClearError();
                ServerControl1 control = new ServerControl1();
                Bitmap bitMap = control.CreateChart();

                bitMap.Save(app.Response.OutputStream, ImageFormat.Gif);

                app.Response.End();
              
                app.Response.Close();
            }
        }

        #endregion
    }
}
